/*
package com.k.kc.util.tree.demo2;

import java.util.*;
import java.util.stream.Collectors;

public class TreeBuildUtil<T extends BaseTreeNode> {
    */
/**
     * 树形集合 唯一标识和树形对象映射 map
     *//*

    private final Map<String, T> allTreeNodeMap;


    public TreeBuildUtil(List<T> allTreeNodeList) {
        this.allTreeNodeMap = allTreeNodeList.stream().collect(Collectors.toMap(T::getKey, node -> node));
    }

    public static <T extends BaseTreeNode> List<BaseTreeNode> transferBaseNode(List<T> sourceTreeList) {
        return new ArrayList<>(Arrays.asList(sourceTreeList.toArray(new BaseTreeNode[0])));
    }

    public static <T extends BaseTreeNode, E extends BaseTreeNode> List<BaseTreeNode> buildBusinessTreeDTO(List<T> sourceTreeList, List<E> businessTreeList) {
        List<BaseTreeNode> source = transferBaseNode(sourceTreeList);
        if(businessTreeList != null && businessTreeList.size() > 0) {
            source.addAll(transferBaseNode(businessTreeList));
        }
        return buildTreeDTO(source, null);
    }

    */
/**
     * 通过全部到处理集合及当前预计根节点集合创建树形列表
     *
     * @param allTreeNodeList
     * @param currentTreeNodeList
     * @param <T>
     * @return
     *//*

    public static <T extends BaseTreeNode> List<T> buildTreeDTO(List<T> allTreeNodeList, List<T> currentTreeNodeList) {
        return new TreeBuildUtil<>(allTreeNodeList).buildTree(currentTreeNodeList);
    }

    */
/**
     * 构建树形列表 如果 currentRootNode 为空则从根节点构建
     *
     * @param currentRootNode 树形列表开始节点集合
     * @throws
     * @title buildTree
     * @author songqinglong 210944941
     * @return: java.util.List<com.command.center.smp.cache.dto.BaseTreeNode>
     *//*

    public List<T> buildTree(List<T> currentRootNode) {
        List<T> treeNodeList = new ArrayList<>();
        List<T> rootNodeList;
        if (currentRootNode != null && currentRootNode.size() > 0) {
            rootNodeList = currentRootNode;
        } else {
            rootNodeList = getTreeRoot();
        }
        rootNodeList.sort(Comparator.comparing(T::getSort));
        for (T rootNode : rootNodeList) {
            fillChildren(rootNode);
            treeNodeList.add(rootNode);
        }
        return treeNodeList;
    }

    */
/**
     * 递归填充子元素
     *
     * @param parentTreeNode 父节点对象
     * @throws
     * @title fillChildren
     * @author songqinglong 210944941
     * @updateTime 2022/5/25 下午1:59
     *//*

    public void fillChildren(BaseTreeNode parentTreeNode) {
        ArrayList<BaseTreeNode> children = getChildTreeNodeList(parentTreeNode);
        if (!children.isEmpty()) {
            for (BaseTreeNode child : children) {
                fillChildren(child);
            }
            parentTreeNode.setChildren(children);
        }
    }

    */
/**
     * 根据父节点 查询所有子节点
     *
     * @param parentTreeNode 父节点对象
     * @throws
     * @title getChildOrgTreeNodeDTOs
     * @author songqinglong 210944941
     * @updateTime 2022/5/25 下午2:01
     * @return: java.util.List<com.command.center.smp.cache.dto.BaseTreeNode < org.apache.poi.ss.formula.functions.T>>
     *//*

    public ArrayList<T> getChildTreeNodeList(BaseTreeNode parentTreeNode) {
        ArrayList<T> childTreeNodeList = new ArrayList<>();
        allTreeNodeMap.forEach((currentKey, node) -> {
            if (parentTreeNode.getKey().equals(node.getParentKey()) && !node.getParentKey().equals(node.getKey())) {
                childTreeNodeList.add(node);
            }
        });

        //childTreeNodeList.sort(Comparator.comparing(T::getObjectType, Comparator.nullsFirst(Comparator.naturalOrder())));
        childTreeNodeList.sort(Comparator.comparing(T::getSort, Comparator.nullsFirst(Comparator.naturalOrder())));
        return childTreeNodeList;
    }

    */
/**
     * 获取根节点集合
     *
     * @throws
     * @title getTreeRoot
     * @author songqinglong 210944941
     * @updateTime 2022/5/25 下午1:54
     * @return: java.util.List<com.command.center.smp.cache.dto.BaseTreeNode < org.apache.poi.ss.formula.functions.T>>
     *//*

    public List<T> getTreeRoot() {
        List<T> rootTreeNodeList = new ArrayList<>();
        allTreeNodeMap.forEach((currentKey, node) -> {
            if (rootOrgTreeNodeDTO(node)) {
                rootTreeNodeList.add(node);
            }
        });
        return rootTreeNodeList;
    }

    */
/**
     * 判断是否为根节点 当前判断无上级为根节点
     *
     * @param treeNode 当前所在节点对象
     * @throws
     * @title rootOrgTreeNodeDTO
     * @author songqinglong 210944941
     * @updateTime 2022/5/25 下午1:54
     * @return: boolean
     *//*

    public boolean rootOrgTreeNodeDTO(BaseTreeNode treeNode) {
        boolean isRootTreeNodeDTO = true;
        if (allTreeNodeMap.containsKey(treeNode.getParentKey()) && !treeNode.getKey().equals(treeNode.getParentKey())) {
            isRootTreeNodeDTO = false;
        }
        return isRootTreeNodeDTO;
    }

}
*/
